<template>
  <div class="app-container" ref="appcontainer">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="100px">
      <!-- <el-form-item label="表码" prop="name"> -->
      <el-input
        v-model="queryParams.tableCode"
        placeholder="表码"
        clearable
        size="small"
        @keyup.enter.native="handleQuery"
        style="width: 8%; margin-right: 10px"
      />
      <el-input
        v-model="queryParams.number"
        placeholder="编号"
        clearable
        size="small"
        style="width: 8%; margin-right: 10px"
        @keyup.enter.native="handleQuery"
      />
      <el-input
        v-model="queryParams.enterpriseName"
        placeholder="委托单位"
        clearable
        size="small"
        style="width: 8%; margin-right: 10px"
        @keyup.enter.native="handleQuery"
      />
      <el-input
        v-model="queryParams.engineeringName"
        placeholder="工程名称"
        clearable
        size="small"
        style="width: 8%; margin-right: 10px"
        @keyup.enter.native="handleQuery"
      />
      <!-- <el-select v-model="queryParams.status" placeholder="状态" style="width:8%;margin-right:10px">
        <el-option v-for="item in mangementOptions" :key="item.dictValue" :label="item.dictLabel"
          :value="item.dictValue"></el-option>
      </el-select> -->
      <el-date-picker
        class="mr10"
        style="width: 20%"
        v-model="queryParams.beginTime"
        type="daterange"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
      ></el-date-picker>
      <!-- </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"
          >查询</el-button
        >
        <!-- <el-button type="primary" size="mini" @click="handleAdd">新增</el-button> -->
        <!-- <el-button type="primary" size="mini" @click="handleStorage">已暂存</el-button> -->
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="" size="mini" @click="handleAdd">新增</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button type="primary" plain icon="" size="mini" @click="handleStorage">已暂存</el-button>
      </el-col>

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>


    <el-table
      v-loading="loading"
      :height="tableHeight"
      :data="enterpriseList"
      @selection-change="handleSelectionChange"
    >
      <!-- <el-table-column type="selection" width="55" align="center" show-overflow-tooltip /> -->
      <el-table-column label="序号" align="center" prop="id" />
      <!-- <el-table-column label="表码" align="center" prop="id" /> -->
      <el-table-column label="编号" align="center" prop="number" />
      <el-table-column
        label="委托单位"
        align="center"
        prop="enterpriseName"
        width="100px"
      />
      <el-table-column
        label="工程名称"
        align="center"
        prop="engineeringName"
        width="200px"
      />
      <el-table-column label="业务类型" align="center" prop="businessType" width="">
        <template slot-scope="scope">
          {{ detection_type[scope.row.businessType] }}
        </template>
      </el-table-column>
      <el-table-column
        label="项目经理"
        align="center"
        prop="businessManagerName"
        width=""
        v-if="is_yezhu==0"
      />
      <!-- <el-table-column label="劳务经理" align="center" prop="businessType" width=""/> -->
      <el-table-column label="试验人员" align="center" prop="businessType" width="" v-if="is_yezhu==0">
        <template slot-scope="scope">
          <div v-if="scope.row.businessType == 'shinei'">
            <div v-for="item in scope.row.sampleList" :key="item.id">
              {{ item.nickName }}
            </div>
          </div>

          <div v-if="scope.row.businessType == 'shiwai'">
            <div v-for="item in scope.row.attachedDataList" :key="item.id">
              {{ item.nickName }}
            </div>
          </div>
        </template>
      </el-table-column>

      <el-table-column
        label="委托日期"
        align="center"
        prop="commissionDate"
        width="80px"
      />
      <el-table-column label="委托文件" align="center" prop="type" width="90px">
        <template slot-scope="scope">
          <div class="imgmod">
            <span
              v-if="scope.row.wordFile"
              class="imgicon"
              @click="downloadFile(scope.row.wordFile)"
            >
              <img src="../../assets/images/download.svg" alt="" />
              <span class="imgflag">w</span>
            </span>
            <span v-else>
              <el-upload
                class="upload-demo"
                ref="upload"
                accept=".doc, .docx"
                :headers="headers"
                :file-list="fileList"
                :action="uploadImgUrl"
                :show-file-list="false"
                :on-success="
                  (response, file, fileList) => {
                    return handleSuccess(response, file, fileList, scope.row);
                  }
                "
              >
                <img src="../../assets/images/upload.svg" alt="" slot="trigger" />
              </el-upload>
            </span>
            <span v-if="scope.row.pdfFile" class="imgicon1">
              <a :href="scope.row.pdfFile" download="filename.pdf">
                <img src="../../assets/images/download.svg" alt="" />
                <span class="imgflag1">p</span>
              </a>
            </span>
            <span v-else>
              <el-upload
                class="upload-demo"
                ref="upload"
                accept=".pdf"
                :headers="headers"
                :file-list="fileList"
                :action="uploadImgUrl"
                :show-file-list="false"
                :on-success="
                  (response, file, fileList) => {
                    return handleSuccess1(response, file, fileList, scope.row);
                  }
                "
              >
                <img src="../../assets/images/upload.svg" alt="" slot="trigger" />
              </el-upload>
            </span>
          </div>
          <!-- <div v-if="scope.row.wordFile" class="xiazaibtn1" style="display: inline-block;margin-left: 10px;"
            @click="onpreviewfile(scope.row.wordFile)">
            <img src="../../assets/images/download.svg" alt="" style="margin-right: 10px;">

          </div>
          <div v-if="scope.row.pdfFile" class="xiazaibtn" style="display: inline-block;"
            @click="onpreview(scope.row.pdfFile)">
            <img src="../../assets/images/download.svg" alt="" style="">

          </div> -->

          <!-- <div v-else style="display: inline-block;">
            <el-upload
              class="upload-demo"
              ref="upload"
              :action="uploadImgUrl"

              :file-list="fileList"
              :auto-upload="false">
              <img src="../../assets/images/upload.svg" alt="" slot="trigger" >
            </el-upload>

          </div> -->
        </template>
      </el-table-column>
      <el-table-column label="附表" align="center" prop="type" width="120px">
        <template slot-scope="scope">
          <!-- <el-button size="mini" type="primary" @click="onUploadTable(scope.row)"
            >上传附表</el-button> -->

          <!-- <fileUpload v-model="scope.row.filetype" @file-type="scope.row.handleFileType()" :isShowTip="false" :showFileList="false"/> -->
          <!-- <div v-for="item in scope.row.attachedList" :key="item.id"> -->
          <span @click="onUploadTable(scope.row)" style="display: block; color: #1176ff;cursor: pointer;">附表 {{
            scope.row.attachedList.length
          }}</span>
          <!-- </div> -->
        </template>
      </el-table-column>
      <el-table-column label="检测项目" align="center" prop="type" width="200px">
        <template slot-scope="scope">
          <div v-if="scope.row.businessType == 'shinei'">
            <div v-for="item in scope.row.sampleList" :key="item.id">
              {{ detectionOptions[item.project] }}
              <a
                style="color: #46a6ff; text-decoration: underline"
                @click="toExperimental"
                >{{ item.number }}</a
              >
            </div>
          </div>

          <div v-if="scope.row.businessType == 'shiwai'">
            <div v-for="item in scope.row.attachedDataList" :key="item.id">
              {{ item.testMethod }}
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="检测报告" align="center" prop="type">
        <template slot-scope="scope">
          <div v-for="item in scope.row.reportList" :key="item.id">
            <!-- <a
              v-if="item.reportFile"
              style="color: #1890ff"
              :href="item.reportHref"
              :download="getFileName(item.reportFile)"
              >{{ getFileName(item.reportFile) }}</a
            > -->
            <el-link :href="item.reportFile" :underline="false" target="_blank">
              <span style="color: #1890ff"> {{ getFileName(item.reportFile) }} </span>
            </el-link>
          </div>
          <!-- <div @click="toTestReport">检测报告1<span style="display:block;color:1176FF">2</span></div>  -->
        </template>
      </el-table-column>

      <!-- <el-table-column label="状态" align="center" prop="type">
        <template slot-scope="scope">
          {{ommission_status[scope.row.status]}}
        </template>
      </el-table-column> -->

      <el-table-column
        label="操作"
        align="center"
        width="100px"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">

          <el-button size="mini" type="text" @click="handledetail(scope.row)" v-if="scope.row.status != 'chushi'">详情</el-button>
          
          <div v-if="scope.row.status=='done'"></div>
          <div v-else>
            <el-button size="mini" type="text" @click="handleAccept(scope.row)"
              v-if="is_yewu==1 && scope.row.status == 'chushi' && scope.row.showStatus !== 2 && scope.row.status !== 2">受理</el-button>

            <el-button size="mini" type="text" @click="handleAssign(scope.row)"
              v-if="scope.row.status == 'souli' && roleId != 6 && roleId != 9">分配</el-button>

            <!-- <el-button size="mini" type="text" @click="handleCollar(scope.row)">领样</el-button> -->
            <!-- <el-button size="mini" type="text" @click="handleReport(scope.row.id)">上传报告</el-button> -->
            <el-button v-if="scope.row.status == 'chushi'" size="mini" type="text"
              @click="handleUpdate(scope.row)">修改</el-button>

            <el-button size="mini" type="text" @click="handleDelete(scope.row)" >删除</el-button>
          </div>

        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 委托单填报 -->
    <el-dialog
      :close-on-click-modal="false"
      :title="title"
      :visible.sync="openDialog"
      width="100%"
      append-to-body
      class="insert"
    >
      <orderDialog
        @getList="getList"
        :rowId="rowId"
        ref="form1"
        @closeOpenDialog="closeOpenDialog"
        :detectionOptions="detectionOptions"
      ></orderDialog>
    </el-dialog>
    <!-- 委托单受理 -->
    <el-dialog
      :close-on-click-modal="false"
      :title="title"
      :visible.sync="openAcceptDialog"
      width="800px"
      append-to-body
    >
      <acceptDialog
        @closeAcceptDialog="closeAcceptDialog"
        @getList="getList"
        :formParams="formParams"
        ref="form2"
      >
      </acceptDialog>
    </el-dialog>
    <el-dialog
      :close-on-click-modal="false"
      :title="title2"
      :visible.sync="orderdetaildialog"
      width="700px"
    >
      <el-form label-width="88px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="表码" prop="ipaddr">
              <span class="text-size">{{ detailObj.tableCode }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="委托单编号" prop="ipaddr">
              <span class="text-size">{{ detailObj.number }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="委托人" prop="ipaddr">
              <span class="text-size">{{ detailObj.userName }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="ipaddr">
              <span class="text-size">{{ detailObj.mobile }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="工程名称" prop="ipaddr">
              <span class="text-size">{{ detailObj.engineeringName }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工程地点" prop="ipaddr">
              <span class="text-size">{{ detailObj.address }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="建设单位" prop="ipaddr">
              <span class="text-size">{{ detailObj.constructionUnit }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="监理单位" prop="ipaddr">
              <span class="text-size">{{ detailObj.supervisionUnit }}</span>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="设计单位" prop="ipaddr">
              <span class="text-size">{{ detailObj.designUnit }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="勘察单位" prop="ipaddr">
              <span class="text-size">{{ detailObj.surveyUnit }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="施工单位" prop="ipaddr">
              <span class="text-size">{{ detailObj.construcUnit }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工程概况" prop="ipaddr">
              <span class="text-size">{{ detailObj.overview }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="委托检测内容" prop="ipaddr">
              <span class="text-size">{{ detailObj.detectionContent }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="检测依据" prop="ipaddr">
              <span class="text-size">{{ detailObj.accordingContent }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="委托日期" prop="ipaddr">
              <span class="text-size">{{ detailObj.commissionDate }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="项目经理" prop="ipaddr">
              <span class="text-size">{{ detailObj.businessManagerName }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="业务类型" prop="ipaddr">
              <span class="text-size">{{
                detailObj.businessType == "shinei" ? "室内检测" : "现场检测"
              }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <!-- <el-form-item label="附表" prop="ipaddr">
              <span class="text-size">{{ detailObj.accordingContent }}</span>
            </el-form-item> -->
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {
  listEnterprise,
  getEnterprise,
  DelEnterpriselist,
  addEnterprise,
  updateEnterprise1,
  exportEnterprise,
  geteditEnterprise,
  acceptanceOrder,
  getDetectionContentChange,
} from "@/api/enterprise/enterprise";
import orderDialog from "./components/orderFallin";
import acceptDialog from "./components/orderAccept";
import { getToken } from "@/utils/auth";
import Cookies from "js-cookie";
import { getProject } from "@/api/project/project";

export default {
  components: { orderDialog, acceptDialog },
  name: "Enterprise",
  data() {
    return {
      detection_type: [],
      title2: "",
      orderdetaildialog: false,
      rowId: "",
      fileList: [],
      headers: { Authorization: "Bearer " + getToken() },
      uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/upload",
      mangementOptions: "",
      wordFilename: "",
      pdfFilename: "",
      filetype: "",
      tableHeight: 0,
      detectionOptions: [],
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      commissionId: "",
      // 总条数
      total: 0,
      // 企业信息表格数据
      enterpriseList: [],
      userId: "",
      // 弹出层标题
      title: "",
      detailObj: "",
      enterpriseNamearr: [],
      // 是否显示弹出层
      openDialog: false,
      openAcceptDialog: false,
      // 企业类型字典
      typeOptions: [],
      // 状态 1=开业，2=停业字典
      statusOptions: [],
      options: [
        {
          label: "11",
          value: "11",
        },
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        code: null,
        type: null,
        status: null,
        number: "",
        job: "",
        jobname: "",
        status1: "",
        timevalue1: "",
      },
      // 表单参数
      formParams: {},
      // 表单校验
      rules: {
        name: [{ required: true, message: "企业名称不能为空", trigger: "blur" }],
        code: [{ required: true, message: "社会信用代码不能为空", trigger: "blur" }],
      },
      roleId: null,
      roles: [],
      enterpriseId: null,
      ommission_status: [],
      is_yezhu:0,
      is_yewu:0,//业务受理员
    };
  },
  created() {
    //当前用户的信息
    let userInfo = JSON.parse(Cookies.get("userinfo"));
    console.log(userInfo)
    this.roles = userInfo.roles;
    this.roleId = userInfo.roleId;
    this.enterpriseId = userInfo.enterpriseId;

    //业主不让看 工程编号 和 项目经理
    for(let i=0; i < this.roles.length;i++){
      if(this.roles[i].roleId == 6 || this.roles[i].roleId == 9){
        this.is_yezhu = 1
      }
      if( this.roles[i].roleId == 2 || this.roles[i].roleId == 3){
        this.is_yewu = 1
      }
    }
    if(userInfo.userId == 1 ){
      this.is_yewu = 1
    }

    this.calHeight();
    // this.getDicts("gc_enterprise_type").then(response => {
    //   this.typeOptions = response.data;
    // });
    // this.getDicts("gc_enterprise_status").then(response => {
    //   this.statusOptions = response.data;
    // });

    this.getDicts("detection_type").then((response) => {
      // this.mangementOptions = response.data;
      let data = response.data;
      let new_arr = [];
      data.forEach(function (item) {
        new_arr[item.dictValue] = item.dictLabel;
      });
      this.detection_type = new_arr;
    });

    //委托单管理状态
    this.getDicts("gc_ommission_status").then((response) => {
      this.mangementOptions = response.data;

      let data = response.data;
      let new_arr = [];
      data.forEach(function (item) {
        new_arr[item.dictValue] = item.dictLabel;
      });
      this.ommission_status = new_arr;
    });
    //  //检测项目
    //  this.getDicts("detection_item_indoor").then(response => {
    //   this.detectionOptions = response.data;
    // });

    //室内字典
    this.getDicts("detection_item_indoor").then((response) => {
      let data = response.data;
      let new_arr = [];
      data.forEach(function (item) {
        new_arr[item.dictValue] = item.dictLabel;
      });
      this.detectionOptions = new_arr;
    });
    this.getList();
  },
  watch: {
    showSearch: "calHeight",
  },
  methods: {
    // 暂存按钮
    handleStorage() {
      // 获取当前用户id
      let userId = JSON.parse(Cookies.get("userinfo")).userId;
      this.queryParams.name = userId;
      this.queryParams.showStatus = 2;
      listEnterprise(this.queryParams).then((res) => {
        this.enterpriseList = res.rows;
        this.total = res.total;
      });
    },
    //委托单详情
    handledetail(row) {
      this.title2 = "委托单详情";
      this.orderdetaildialog = true;
      geteditEnterprise(row.id).then((res) => {
        this.detailObj = res.data;
      });
    },
    goback() {
      this.$router.back();
    },
    async handleSuccess(response, file, fileList, row) {
      this.wordFilename = response.originalFilename;

      if (response.code == 200) {
        try {
          let obj = {
            id: row.id,
            wordFile: response.url,
          };
          let res = await updateEnterprise1(obj);
          if (res.code == 200) {
            this.$message.success(`上传成功`);
            geteditEnterprise(obj.id).then((response) => {
              this.sendNotice(response, 1);
            });
            this.getList();
          }
        } catch (err) {
          this.$message.error(res.msg);
        }
      }
    },

    sendNotice(data, type) {},
    selectUserId(data) {
      getProject(data).then((response) => {
        this.userId = response.data.projectManagerId;
      });
    },
    async handleSuccess1(response, file, fileList, row) {
      this.pdfFilename = response.originalFilename;
      if (response.code == 200) {
        this.$message.success(`上传成功`);
        try {
          let obj = {
            id: row.id,
            pdfFile: response.url,
          };
          let res = await updateEnterprise1(obj);
          if (res.code == 200) {
            this.$message.success(`上传成功`);
            geteditEnterprise(obj.id).then((response) => {
              this.sendNotice(response, 1);
            });
            this.getList();
          }
        } catch (err) {
          this.$message.error(res.msg);
        }
      }
    },
    //上传附表
    onUploadTable(row) {
      let obj = {
        id: row.id,
        businessType: row.businessType,
        engineeringName: row.engineeringName,
        number: row.number,
      };

      this.$router.push({ name: "tableManagement", query: { row: JSON.stringify(obj) } });
    },
    handleFileType(file) {
      let ext = file.name.slice(file.name.lastIndexOf(".") + 1).toLowerCase();
      if (ext === "doc" || ext === "docx") {
        this.formParams.wordFile = file.name;
      } else if (ext === "pdf") {
        this.formParams.pdfFile = file.name;
      }
      console.log("文件类型:", ext, "文件名:", file.name);
    },
    toTestReport() {
      this.$router.push({ name: "reportsManagement" });
    },
    toTableList() {
      this.$router.push({ name: "tableManagement" });
    },
    toExperimental() {
      this.$router.push({
        name: "experimentalSample",
        query: { row: JSON.stringify(row) },
      });
    },
    //分配
    handleAssign(row) {
      this.$router.push({
        name: "experimentalSample",
        query: { row: JSON.stringify(row) },
      });
    },
    closeAcceptDialog() {
      this.openAcceptDialog = false;
    },
    closeOpenDialog() {
      this.openDialog = false;
    },
    calHeight() {
      this.$nextTick(() => {
        const rect = this.$refs.appcontainer.getBoundingClientRect();
        let height = this.$refs.queryForm.$el.offsetHeight;
        this.tableHeight = rect.height - height - 120;
      });
    },
    downloadFile(url) {
      const link = document.createElement("a");
      const filename = this.wordFilename;
      link.href = url;
      link.download = filename || "download";
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link);
    },
    async downloadFile1(pdfUrl) {
      const response = await axios({
        url: pdfUrl,
        method: "GET",
        responseType: "blob",
      });
      const url = window.URL.createObjectURL(new Blob([response.data]));
      const link = document.createElement("a");
      link.href = url;
      link.setAttribute("download", "file.pdf");
      document.body.appendChild(link);
      link.click();

      //  const link = document.createElement("a");
      // const filename = this.pdfFilename
      // link.href = url;
      // link.download = filename || "download";
      // document.body.appendChild(link);
      // link.click();
      // document.body.removeChild(link);
    },

    //委托文件pdf下载
    onpreview(fileName) {
      const data = "http://gczj.yc0914group.com" + fileName; // 文件的URL地址
      if (!data) {
        return;
      }
      let url = window.URL.createObjectURL(new Blob([data]));
      let link = document.createElement("a");
      link.style.display = "none";
      link.href = url;
      link.setAttribute("download", fileName);
      document.body.appendChild(link);
      link.click();
      // const fileUrl = 'http://gczj.yc0914group.com' + fileName; // 文件的URL地址
      // const link = document.createElement('a');
      // link.href = fileUrl;
      // link.setAttribute('download', fileName);
      // link.click();
    },
    /** 查询企业信息列表 */
    getList(type = null) {
      // for (let i = 0; i < this.roles.length; i++) {
      //   if (this.roles[i].roleId == 6 || this.roles[i].roleId == 9) {
      //     this.queryParams.enterpriseId = this.enterpriseId;
      //     break;
      //   }
      // }

      let user = JSON.parse(Cookies.get("userinfo"));
      if (type == "zc") {
        this.queryParams.name = user.userId;
        this.queryParams.showStatus = 2;
      }else{
        this.queryParams.showStatus = 3;
      }
      this.loading = true;
      
      for (let i = 0; i < this.roles.length; i++) {
        if (this.roles[i].roleId == 6) {
          this.queryParams.enterpriseId = this.enterpriseId;
          break;
        }
      }

      this.queryParams.isRoleShow = 1
      listEnterprise(this.queryParams).then((response) => {
        let data = response.rows;
        data.forEach(function (item) {
          item.reportList.forEach(function (item2) {
            item2.reportHref = process.env.VUE_APP_BASE_API + item2.reportFile;
          });
        });
        console.log("kkkkk");
        console.log(data);
        if (type == "zc") {
          this.enterpriseList = data;
        } else {
          this.enterpriseList = data.filter((item) => item.showStatus != 2);
        }
        // this.enterpriseNamearr = this.enterpriseList.map(item => {
        //   return {
        //     enterpriseId: item.enterpriseId,
        //     enterpriseName: item.enterpriseName
        //   }
        // })
        this.total = response.total;
        this.loading = false;
      });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

    // 表单重置
    reset() {
      this.formParams = {
        engineeringName: "",
        commissionDate: "",
        accordingContent: "",
        detectionContent: "",
        engineeringName: "",
        mobile: "",
        enterpriseName: "",
        name: "",
        pdfFile: "",
        wordFile: "",
      };
      this.resetForm("formParams");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.showSearch = false;
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleAccept(row) {
      const id = row.id || this.ids;

      geteditEnterprise(id).then((response) => {
        this.formParams = response.data;
        this.openAcceptDialog = true;
        this.title = "委托单受理";
      });
    },
    handleCollar() {
      this.$router.push({ name: "experimentalSample" });
    },
    handleReport(id) {
      console.log(id);
      this.$router.push({ name: "reportsManagement", query: { id: id } });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.name = null;
      this.queryParams.showStatus = null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      let userInfo = JSON.parse(Cookies.get("userinfo"));
      this.openDialog = true;
      this.title = "委托单填报";
      console.log(this.$refs.form1);
      this.$refs.form1.reset();
      this.$nextTick(() => {
        this.$refs.form1.name = userInfo.userId;
        this.$refs.form1.name1 = userInfo.userName;
        this.$refs.form1.mobile = userInfo.phonenumber;
      });

      this.rowId = "";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      if (row.id) {
        this.rowId = row.id;
      }
      
      this.openDialog = true;
      this.title = "编辑委托单";
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      // 判断当前用户角色吧
      // let roleId = JSON.parse(Cookies.get("userinfo")).roleId;
      // if (roleId != 3 && roleId != 4 && roleId != 5) {
      //   this.$message.error("无权限操作");
      //   return;
      // }
      // 判断状态
      if (row.status != 'chushi') {
        this.$message.error("委托单已受理，无法删除");
        return;
      }
      this.$confirm("是否确认删除?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return DelEnterpriselist(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有企业信息数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportEnterprise(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
    // 获取文件名称
    getFileName(name) {
      if (name) {
        console.log(name);
        if (name.lastIndexOf("/") > -1) {
          return name.slice(name.lastIndexOf("/") + 1).toLowerCase();
        } else {
          return "";
        }
      } else {
        return "";
      }
    },
  },
};
</script>
<style scoped lang="scss">

// ::v-deep .el-dialog__wrapper{
//   background: #fff !important;
// }
::v-deep .el-dialog{
  min-height: 100vh !important;
  margin-top: 0 !important;
}
// .insert{
//   height: 100% !important;
//   margin-top: 0 !important;
// }
.margin-bottom-10 {
  margin-bottom: 10px;
}

.imgicon {
  display: inline-block;
  margin-left: 6px;
  position: relative;
  cursor: pointer;
}

.imgicon1 {
  display: inline-block;
  margin-left: 6px;
  position: relative;
  cursor: pointer;
}

.imgflag {
  display: block;
  color: #fff;
  position: absolute;
  top: 0;
  left: 0px;
}

.imgflag1 {
  display: block;
  color: #fff;
  position: absolute;
  top: 0;
  left: 0px;
}

.imgmod span {
  display: inline-block;
  margin-left: 5px;
}

.sampleList {
  span {
    display: inline-block;
    margin-left: 10px;
  }
}
</style>
